<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@ page import="java.util.*,java.text.*"%>
    <%@page import="dao.*" %>
    <%@page import="servlet.*" %>
    <jsp:include page="heading.jsp"/>
<!DOCTYPE html >
<html>
<head>
<style type="text/css">
	.div1{
	width:80%;
	height:300px;
	margin:0px auto;
	}
.div2{
	float:left;
}
.div2 img{
	width:200px;
	height:200px;
}

.div3{
	float:left;
	margin-left:200px;
	margin-top:30px;
	
}
.mybtn{
width: 86px;
text-align: center;
line-height: 100%;
padding-top: 0.5em;
padding-right: 2em;
padding-bottom: 0.55em;
padding-left: 2em;
font-family: "Arial Black", Gadget, sans-serif;
font-size: 14px;
font-style: normal;
font-variant: normal;
font-weight: normal;
text-decoration: none;
margin-top: 0px;
margin-right: 2px;
margin-bottom: 0px;
margin-left: 2px;
vertical-align: text-bottom;
display: inline-block;
cursor: pointer;
zoom:1;
outline-width:medium;
outline-color:inherit;
font-size-adjust:none;
font-stretch:normal;
border-top-left-radius:0.5em;
border-top-right-radius:0.5em;
border-bottom-left-radius:0.5em;
border-bottom-right-radius:0.5em;
box-shadow:0px 1px 2px rgba(0,0,0,0.2);
color:#fefee9;
border-top-color:#da7c0c;
border-right-color:#da7c0c;
border-bottom-color:#da7c0c;
border-left-color:#da7c0c;
border-top-width:1px;
border-right-width:1px;
border-bottom-width:1px;
border-left-width:1px;
border-top-style:solid;
border-right-style:solid;
border-bottom-style:solid;
border-left-style:solid;
background-image:none;
background-attachment:scroll;
background-repeat:repeat;
background-position-x:0%;
background-position-y:0%;
background-size:auto;
background-origin:padding-box;
background-clip:padding-box;
background-color:#f78d1d;
}
</style>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>购物车</title>
</head>
<body>
<div class="div1">
		<div class="div2">
		<%
		Map cart = (Map) session.getAttribute("cart");
		double total = 0;
		if (cart == null || cart.size() == 0)
			out.println("<p>购物车当前为空.</p>");
		else {
			// 创建用于显示内容的变量
			Set cartItems = cart.keySet();
			Object[] id = cartItems.toArray();
			Goods good;
			CartItem cartItem;
			int quantity;
			double price, subtotal;
	%>
		
			<%
				int i = 0;
					while (i <id.length) {
						// 计算总和
						cartItem = (CartItem) cart.get((String) id[i]);
						good = cartItem.getGood();
						quantity = cartItem.getQuantity();
						price = good.getPrice();
						subtotal = quantity * price;
						total += subtotal;
						i++;
			%>
		
    	<img src="<%=request.getContextPath()%>/images/<%=good.getImage()%>">
    	
   		<div class="div3">
    	<table>
    	<tr><td>商品名称：<%=good.getName()%></td></tr>
        	<tr><td>数量<%=quantity%></td></tr>
        	<tr><td>价格：<%=new DecimalFormat("0.00").format(price)%></td></tr>
            <tr><td>小计<%=new DecimalFormat("0.00").format(subtotal)%></td></tr>
    		
			<%
				}
			%>
			<tr>
				<td >
					总计：<%=new DecimalFormat("0.00").format(total)%>
				</td>
			</tr>
		
		<%
			session.setAttribute("total", new Double(total));
			}
		%>
		<tr><td><form method="post" action="<%=request.getContextPath()%>/goodview.jsp"><input type="submit" value="继续购物" class="mybtn"></form></td>
            <td><form method="post" action="<%=request.getContextPath()%>/order.jsp"><input type="submit" value="结账" class="mybtn"></form></td>
            </tr>
        </table>
        </div>
        </div>
        </div>

</body>
</html>